param($installPath, $toolsPath, $package, $project)
Write-Host "Adding Microsoft Visual C++ 2013 Runtime Package for Windows Phone"
$project.Object.References.AddSDK("Microsoft Visual C++ 2013 Runtime Package for Windows Phone", "Microsoft.VCLibs, Version=12.0")

     
$packageName = $package.Id + '.' + $package.Version;
$packageId = $package.Id;

# Full assembly name is required
Add-Type -AssemblyName 'Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

$projectCollection = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection
 
# There is no indexer on ICollection<T> and we cannot call
# Enumerable.First<T> because Powershell does not support it easily and
# we do not want to end up MethodInfo.MakeGenericMethod.
$allProjects = $projectCollection.GetLoadedProjects($project.Object.Project.FullName).GetEnumerator(); 

# Write-Host $project.Object.Project.FullName
if($allProjects.MoveNext())
{
# Write-Host $allProjects.Current
	foreach($item in $allprojects.current.getitems('reference'))
	{
		$hintpath = $item.getmetadatavalue("hintpath")
		 
		$newhintpath = $hintpath -replace "lib", "build"
		$newhintpath = $newhintpath -replace "wpa", "wpa\`$(PlatformTarget)"
		$newhintpath = $newhintpath -replace "netcore45", "netcore45\`$(PlatformTarget)"
		 
		# $newhintpath = $hintpath -replace $packageid + ".*?\\", "$packagename\\"
	 
		if ($hintpath -ne $newhintpath)
		{
			write-host "updating $hintpath to $newhintpath"
			$item.setmetadatavalue("hintpath", $newhintpath);
		}
	}
}
